#include "RedBlackTree.h"
#include "Set.h"
#include "Map.h"

namespace rtx
{
	void TestSet()
	{
		set<int> s;
		s.insert(3);
		s.insert(2);
		s.insert(1);
		s.insert(5);
		s.insert(3);
		s.insert(6);
		s.insert(4);
		s.insert(9);
		s.insert(7);

		set<int>::iterator it = s.begin();
		while (it != s.end())
		{
			cout << *it << " ";
			++it;
		}
		cout << endl;
	}

	void TestMap()
	{
		string arr[] = { "苹果", "西瓜", "苹果", "西瓜", "苹果", "苹果", "西瓜", "苹果", "香蕉", "苹果", "香蕉" };

		map<string, int> countMap;
		for (auto& str : arr)
		{
			// 1、str不在countMap中，插入pair(str, int()),然后在对返回次数++
			// 2、str在countMap中，返回value(次数)的引用，次数++;
			countMap[str]++;
		}

		map<string, int>::iterator it = countMap.begin();
		while (it != countMap.end())
		{
			cout << it->first << ":" << it->second << endl;
			++it;
		}
		cout << endl;

		for (const auto& kv : countMap) // 范围for也能用了(傻瓜替换)
		{
			cout << kv.first << ":" << kv.second << endl;
		}
	}
}

int main()
{
	rtx::TestSet();
	rtx::TestMap();

	return 0;
}